import 'dart:async';

import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../provider/LoginProvider.dart';
import '../xcm/xcm.dart';

class CsmPage extends StatefulWidget {
  @override
  _CsmPageState createState() => _CsmPageState();
}

class _CsmPageState extends State<CsmPage> {

  late ScrollController controller = ScrollController(initialScrollOffset: 100);

  late double count = 1;

  late String name = context.read<LoginProvider>().getAliertName() != "null"?context.read<LoginProvider>().getAliertName():"张三风";

  late String city = context.read<LoginProvider>().getAliertAddress() != "null"?context.read<LoginProvider>().getAliertAddress():"龙门阵街道";



  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    controller.addListener(() {
      print(controller.offset.toString());
    });

    getListener();

  }
  @override
  void dispose() {
    // TODO: implement dispose
    controller.dispose();
    super.dispose();
  }

  void getListener() {
    const timeout = const Duration(seconds: 1);
    Timer.periodic(timeout, (timer) {
      //callback function
      //1s 回调一次
      // print('afterTimer='+DateTime.now().toString());
      setState(() {
        count += 1;
      });
      print(count);
      if (count < 7) {
        controller.animateTo(3300,
            duration: Duration(seconds: 10), curve: Curves.linear);
      } else {
        // _controller.animateTo(300,duration: Duration(seconds: 1),curve: Curves.linear);
        controller.jumpTo(150);
        setState(() {
          count = 1;
        });
      }

      //print(count.toString());
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      child: Column(
        children: [
          Container(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: Stack(
              children: [
                Positioned(
                  top: 0,
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    height: MediaQuery.of(context).size.height,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage("lib/assets/csm/bj002.png"),
                          fit: BoxFit.fill),
                    ),
                    child: ListView(
                      children: [
                        Container(
                          width: MediaQuery.of(context).size.width,
                          height: 906,
                          //color: Colors.lightGreen,
                          child: Stack(
                            alignment: Alignment.center,
                            children: [
                              Positioned(
                                bottom: 0,
                                child: Container(
                                  width: MediaQuery.of(context).size.width,
                                  height: 400,
                                  decoration: BoxDecoration(
                                      image: DecorationImage(
                                          image: AssetImage(
                                              "lib/assets/csm/bottom002.png"),
                                          fit: BoxFit.fill)),
                                ),
                              ),
                              Positioned(
                                top: 0,
                                child: Container(
                                  width: MediaQuery.of(context).size.width,
                                  height: 40,
                                  //color: Colors.lightGreenAccent,
                                  child: Row(
                                    children: [
                                      SizedBox(
                                        width: 10,
                                      ),
                                      Icon(
                                        Icons.arrow_back_ios_sharp,
                                        color: Colors.white,
                                        size: 20,
                                      ),
                                      SizedBox(
                                        width: 82,
                                      ),
                                      Text(
                                        "粤康码场所通行",
                                        style: TextStyle(
                                            fontSize: 20, color: Colors.white),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                              Positioned(
                                top: 0,
                                child: Container(
                                  width: MediaQuery.of(context).size.width,
                                  height: 400,
                                  //color: Colors.green,
                                  child: ListView(
                                    controller: controller,
                                    children: [
                                      Container(
                                        width: 500,
                                        height: 5000,
                                        decoration: BoxDecoration(
                                            image: DecorationImage(
                                                image: AssetImage(
                                                    "lib/assets/csm/qiqiu002.png"),
                                                fit: BoxFit.cover)),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                              Positioned(
                                top: 170,
                                child: Padding(
                                  padding: EdgeInsets.only(
                                      left: 0, right: 0, top: 0),
                                  child: InkWell(
                                    onTap: (){
                                      print("...点击行程卡...");

                                      showModalBottomSheet(
                                          backgroundColor:
                                          Color.fromRGBO(
                                              1, 1, 1, 0),
                                          //barrierColor: Color.fromRGBO(100, 100, 100, 1),//
                                          context: context,
                                          isScrollControlled: true,
                                          elevation: 10,
                                          shape:
                                          RoundedRectangleBorder(
                                              borderRadius:
                                              BorderRadius
                                                  .only(
                                                topLeft:
                                                Radius.circular(15),
                                                topRight:
                                                Radius.circular(15),
                                                bottomLeft:
                                                Radius.circular(0),
                                                bottomRight:
                                                Radius.circular(0),
                                              )),
                                          builder: (BuildContext
                                          context) {
                                            return Container(
                                              alignment: Alignment
                                                  .bottomCenter,
                                              //color: Colors.yellow,
                                              height: MediaQuery.of(
                                                  context)
                                                  .size
                                                  .height -
                                                  110,
                                              child: Column(
                                                mainAxisAlignment:
                                                MainAxisAlignment
                                                    .start,
                                                children: [
                                                  Padding(
                                                    padding: EdgeInsets
                                                        .only(
                                                        left:
                                                        10,
                                                        right:
                                                        10),
                                                    child:
                                                    Container(
                                                      alignment:
                                                      Alignment
                                                          .bottomCenter,
                                                      height: 35,
                                                      width: MediaQuery.of(
                                                          context)
                                                          .size
                                                          .width,
                                                      child: Row(
                                                        mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .spaceBetween,
                                                        children: [
                                                          Container(
                                                            width:
                                                            180,
                                                            height:
                                                            45,
                                                            child:
                                                            Row(
                                                              mainAxisAlignment:
                                                              MainAxisAlignment.start,
                                                              children: [
                                                                Container(
                                                                  alignment: Alignment.center,
                                                                  width: 20,
                                                                  height: 20,
                                                                  decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), color: Colors.white),
                                                                  child: Padding(
                                                                    padding: EdgeInsets.all(3),
                                                                    child: Container(
                                                                      width: 14,
                                                                      height: 14,
                                                                      decoration: BoxDecoration(borderRadius: BorderRadius.circular(14), border: Border.all(width: 1), image: DecorationImage(image: AssetImage("lib/assets/ykm/jt2.png"))),
                                                                    ),
                                                                  ),
                                                                ),
                                                                Container(
                                                                  child: Text(
                                                                    " 通信行程卡 提供服务 >",
                                                                    style: TextStyle(color: Colors.white),
                                                                  ),
                                                                ),
                                                              ],
                                                            ),
                                                          ),
                                                          InkWell(
                                                            onTap:
                                                                () {},
                                                            child:
                                                            Padding(
                                                              padding:
                                                              EdgeInsets.only(bottom: 5),
                                                              child:
                                                              Container(
                                                                alignment:
                                                                Alignment.center,
                                                                width:
                                                                18,
                                                                height:
                                                                18,
                                                                decoration:
                                                                BoxDecoration(
                                                                  color: Color.fromRGBO(69, 73, 74, 0.5),
                                                                  borderRadius: BorderRadius.circular(16),
                                                                ),
                                                                child:
                                                                Container(
                                                                  width: 14,
                                                                  height: 14,
                                                                  child: Image.asset(
                                                                    "lib/assets/ykm/xxx.png",
                                                                    fit: BoxFit.fill,
                                                                  ),
                                                                ),
                                                              ),
                                                            ),
                                                          )
                                                        ],
                                                      ),
                                                    ),
                                                  ),
                                                  Stack(
                                                    children: [
                                                      Container(
                                                        height: 585,
                                                        width: MediaQuery.of(
                                                            context)
                                                            .size
                                                            .width,
                                                        child:
                                                        Column(
                                                          mainAxisAlignment:
                                                          MainAxisAlignment
                                                              .center,
                                                          children: [
                                                            Container(
                                                              width: MediaQuery.of(context)
                                                                  .size
                                                                  .width,
                                                              height:
                                                              45,
                                                              decoration: BoxDecoration(
                                                                  color: Colors.white,
                                                                  borderRadius: BorderRadius.only(
                                                                    topLeft: Radius.circular(15),
                                                                    topRight: Radius.circular(15),
                                                                    bottomLeft: Radius.circular(0),
                                                                    bottomRight: Radius.circular(0),
                                                                  )),
                                                              alignment:
                                                              Alignment.center,
                                                              child:
                                                              Text(
                                                                "通信行程卡",
                                                                style:
                                                                TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
                                                              ),
                                                            ),
                                                            XcmPage()
                                                            // CityPage()
                                                          ],
                                                        ),
                                                      ),

                                                    ],
                                                  ),
                                                ],
                                              ),
                                            );
                                          });
                                    },
                                    child: Container(
                                      width: 300,
                                      height: 400,
                                      decoration: BoxDecoration(
                                        image: DecorationImage(
                                            image: AssetImage(
                                                "lib/assets/csm/erwm002.png"),
                                            fit: BoxFit.fill),
                                      ),
                                      //child: Container(width: 50,height: 50,color: Colors.teal,),
                                      child: Column(
                                        children: [
                                          Text(
                                            "场所ID 78**33",
                                            style: TextStyle(
                                                fontSize: 12,
                                                height: 1.3,
                                                color: Color.fromRGBO(
                                                    134, 151, 172, 1)),
                                          ),
                                          Text(
                                            "" + city,
                                            style: TextStyle(
                                                fontSize: 22,
                                                height: 2,
                                                color: Color.fromRGBO(5, 5, 5, 1),
                                                fontWeight: FontWeight.w600),
                                          ),
                                          Text(
                                            name +
                                                " " +
                                                DateTime.now()
                                                    .toString()
                                                    .substring(0, 18) +
                                                "1",
                                            style: TextStyle(
                                                fontSize: 12,
                                                height: 1.5,
                                                color: Color.fromRGBO(
                                                    154, 154, 154, 1)),
                                          ),
                                          SizedBox(
                                            height: 237,
                                          ),
                                          Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceAround,
                                            children: [
                                              // SizedBox(width: 0,),
                                              Padding(
                                                padding:
                                                    EdgeInsets.only(left: 10),
                                                child: Container(
                                                  alignment: Alignment.center,
                                                  width: 144,
                                                  child: Text(
                                                    "" +
                                                        DateTime.now()
                                                            .year
                                                            .toString() +
                                                        "-" +
                                                        DateTime.now()
                                                            .month
                                                            .toString() +
                                                        "-" +
                                                        (DateTime.now().day < 10
                                                            ? "0" +
                                                                (DateTime.now()
                                                                        .day)
                                                                    .toString()
                                                            : (DateTime.now().day)
                                                                .toString()) +
                                                        " " +
                                                        "01:10:28",
                                                    style: TextStyle(
                                                        color: Colors.white,
                                                        fontSize: 10),
                                                  ),
                                                ),
                                              ),

                                              Padding(
                                                padding:
                                                    EdgeInsets.only(right: 10),
                                                child: Container(
                                                  alignment: Alignment.center,
                                                  width: 135,
                                                  child: Text(
                                                    "2021-12-01",
                                                    style: TextStyle(
                                                        color: Color.fromRGBO(
                                                            167, 167, 167, 1)),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                              Positioned(
                                top: 70,
                                child: Padding(
                                  padding:
                                      EdgeInsets.only(left: 100, right: 80),
                                  child: Container(
                                    alignment: Alignment.center,
                                    width: 160,
                                    height: 100,
                                    decoration: BoxDecoration(
                                      image: DecorationImage(
                                          image: AssetImage(
                                              "lib/assets/csm/top002.png"),
                                          fit: BoxFit.fill),
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                Positioned(
                  top: 55,
                  right: 10,
                  child: Container(
                    width: 95,
                    height: 38,
                    //color: Colors.orange,
                    child: Container(
                      width: 95,
                      height: 38,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(33),
                        color: Color.fromRGBO(47, 115, 217, 0.5),
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Container(
                            width: 22,
                            height: 22,
                            child: Image.asset("lib/assets/ykm/gd.png"),
                          ),
                          SizedBox(
                            width: 15,
                          ),
                          Container(
                            width: 22,
                            height: 22,
                            child: Image.asset("lib/assets/ykm/yd.png"),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
